package com.apache.flow.core.dao;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.apache.core.orm.hibernate.ApacheBaseDao;
import com.apache.flow.vo.FlowLockQvo;
import com.apache.tools.StrUtil;
import com.apache.uct.common.entity.Lock;

@Repository
public class FlowLockDao extends ApacheBaseDao<Lock, String> {
	/**
	 * 
	 * @param qvo
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws UctLockException
	 * <p>@description 获取所有资源
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:32:06
	 */
	public List<Lock> getLockListByQvo(FlowLockQvo qvo, int pageNo, int pageSize) throws Exception {
		StringBuffer sb = new StringBuffer("from Lock where 1=1 ");
		return this.find(sb.toString());
	}

	/**
	 * 
	 * @return
	 * @throws UctLockException
	 * <p>@description 获取所有可用的资源
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:32:34
	 */
	public List<Lock> getAllLock() throws Exception {
		String hql = "from Lock where 1=1 and lockStatus='1'";
		return this.find(hql, new HashMap<String, String>());
	}

	/**
	 * 
	 * @param lock Lock对象
	 * @return
	 * <p>@description 根据条件查询Lock对象
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:33:00
	 */
	public List<Lock> getLockByProperty(Lock lock) {
		String lockType = StrUtil.doNull(lock.getLockType(), "");
		String actFullEname = StrUtil.doNull(lock.getActFullEname(), "");
		String sysEname = StrUtil.doNull(lock.getSysEname(), "");
		String hql = "from Lock where 1=1 and lockStatus='1' ";
		if (!"".equals(lockType)) {
			hql += " and lockType = '" + lockType + "' ";
		}
		if (!"".equals(actFullEname)) {
			hql += " and actFullEname = '" + actFullEname + "' ";
		}
		if (!"".equals(sysEname)) {
			hql += " and sysEname = '" + sysEname + "' ";
		}
		return this.find(hql, new HashMap<String, String>());
	}

	/**
	 * 
	 * @param sysId 系统标识
	 * @return
	 * <p>@description 根据系统标识获取任务资源
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-7-29 下午04:33:48
	 */
	public List<Lock> getLockBySysId(String sysId) {
		String hql = "from Lock where 1=1 and sysId='" + sysId + "' and lockType !='System' ";
		return this.find(hql);
	}

}
